#!/bin/bash
mydir=`dirname "$0"`
uninstallToolPath="$mydir/UninstallerTool"
installBasePath="${2%/Red Giant FxPlug3}"
installSubPath="Red Giant FxPlug3"
payloadFile="${PACKAGE_PATH}/../../Resources/Payloads/Primatte.FXPLUG3.351066f7.pax.gz"
productName="PrimatteKeyer"
productNumber="112"
installProductStr=`/usr/bin/grep -i "\<${productName}\>" "/tmp/rgs.C867B87B_3A5F_42DF_A83E_089FEDA01D63_${productNumber}"`
if [ ! -z "${installProductStr}" ]; then
    /usr/bin/xattr -d com.apple.quarantine "${payloadFile}"
    /bin/mkdir -p "$2/${installSubPath}"
    pushd "$2/${installSubPath}"
    /bin/pax -rzf "${payloadFile}"
    popd
    "$uninstallToolPath" -a "keying" "Keying Suite" -a "keying.primattekeyer" "Primatte Keyer" "${installBasePath}/${installSubPath}/PrimatteKeyerApp.app" "${installBasePath}/Red Giant FxPlug3"
    if [ -x "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister" ]; then
        "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister" "$2/${installSubPath}/PrimatteKeyerApp.app"
    fi
    if [ -x "/usr/bin/pluginkit" ]; then
        pushd "$2/${installSubPath}/"
        if [ -d "PrimatteKeyerApp.app/Contents/PlugIns" ]; then
            "/usr/bin/pluginkit" -a "PrimatteKeyerApp.app/Contents/PlugIns/*"
            fi
        popd
    fi
fi
